<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Apply extends CI_Controller {
	
	function __construct(){
		parent::__construct();
		$this->load->helper(array('link'));
		$this->load->library(array("form_validation"));
		$this->load->model(array('apply_model'));
		
		$this->form_validation->set_rules("fullname_contact","Full name","trim|xss_clean");
		$this->form_validation->set_rules("phone_contact","Phone number","trim|xss_clean");
		$this->form_validation->set_rules("email_contact","Email","trim|xss_clean");
		$this->form_validation->set_rules("message","Message","trim|xss_clean");
		session_start();
	}

		
	function step_1(){
		if($_SERVER['REQUEST_METHOD'] == 'POST'){
			$time	=	md5(time());
			$para	=	array(
								'session'		=>	$time,
								'purpose'		=>	$this->input->post('purpose'),
								'number_visa'	=>	$this->input->post('number_visa'),
								'type_visa'		=>	$this->input->post('type_visa'),
								'rush_services'	=>	$this->input->post('rush_service'),
								'step' 			=> 	1,
							   	'time'			=>	time(),
							   	'ip'			=>	$_SERVER['REMOTE_ADDR']
							 );
			
			$customer_id			=	$this->apply_model->save_session($para);
			$_SESSION['session']	=	$customer_id;
			redirect('step_2', 'refresh');
		}
		#get data.
		$type_of_visa				=	$this->apply_model->get_type_of_visa();
		$timezone 					= 	+ intval(7); //(GMT +7:00)
		
		#assign data.
		$data['type_of_visa']		=	$type_of_visa;
		$data['timezone']			=	$timezone;
		
		$data['tpl_file']			=	"step_1";
		$this->load->view('pagelayout/index', $data);
	}
	
	
	
	
	function step_2(){
		if($_SERVER['REQUEST_METHOD'] == 'POST'){
			$number_applicant				=	$_POST['hidden_number_visa'];
			$applicant_info					=	array();

			if($this->form_validation->run() == TRUE){
				$contact_info					=	array();
				$contact_info['name']			=	$this->input->post('fullname_contact');
				$contact_info['email']			=	$this->input->post('email_contact');
				$contact_info['phone']			=	$this->input->post('phone_contact');
				$contact_info['purpose']		=	$this->input->post('hidden_purpose');
				$contact_info['message']		=	$this->input->post('message');
				$contact_info['amount_visa']	=	$this->input->post('hidden_number_visa');
				$contact_info['type_visa']		=	$this->input->post('hidden_type_visa');
				$contact_info['services']		=	$this->input->post('hidden_rush_service');
				$contact_info['date_arrival']	=	$this->input->post('arrival_date');
				$contact_info['date_exit']		=	$this->input->post('exit_date');
				$contact_info['arrival_port']	=	$this->input->post('arrival_port');
				$contact_info['nationality']	=	$this->input->post('nationality_contact');
				$contact_info['flight_number']	=	$this->input->post('flight_number');
				
				#insert all information into DB.
				$customer_id					=	$this->apply_model->add_contact($contact_info);
			}
				
			for ($i = 1; $i <= $number_applicant; $i++){
				#get value from step 2 - form.
				$name					=	'full_name_'.$i;
				$passport_number		=	'passport_number_'.$i;
				$passport_expiration	=	'passport_expiration_'.$i;
				$nationality			=	'nationality_'.$i;
				$gender					=	'gender_'.$i;
				
				#get expiration of passport.
				$expiration_month		=	'expiration_mm_'.$i;
				$expiration_day			=	'expiration_dd_'.$i;
				$expiration_year		=	'expiration_yyyy_'.$i;
				$ex_day					=	$this->input->post($expiration_day);
				$ex_month				=	$this->input->post($expiration_month);
				$ex_year				=	$this->input->post($expiration_year);
				
				#get birth date.
				$birth_month			=	'birth_mm_'.$i;
				$birth_day				=	'birth_dd_'.$i;
				$birth_year				=	'birth_yyyy_'.$i;
				$month_of_birth			=	$this->input->post($birth_month);
				$day_of_birth			=	$this->input->post($birth_day);
				$year_of_birth			=	$this->input->post($birth_year);

				$date_birth_integration	=	$month_of_birth.'/'.$day_of_birth.'/'.$year_of_birth;
				
				#set rule for name.
				$this->form_validation->set_rules("full_name_$i","Name","trim|xss_clean");
				
				
				#assign data to an array.
				if($this->form_validation->run() == TRUE){
					$applicant_info[$i]['customer_id']	=	$customer_id;
					$applicant_info[$i]['full_name']	=	$this->input->post($name);
					$applicant_info[$i]['passport']		=	$this->input->post($passport_number);
					$applicant_info[$i]['expiration']	=	$ex_month.'/'.$ex_day.'/'.$ex_year;
					$applicant_info[$i]['nationality']	=	$this->input->post($nationality);
					$applicant_info[$i]['birth_date']	=	$date_birth_integration;
					$applicant_info[$i]['gender']		=	$this->input->post($gender);
					
					#insert into DB.
					$this->apply_model->add_applicants($applicant_info[$i]);
				}
				
				
			}
			
			#jump to step 3.
			redirect('step_3/'.$customer_id, 'refresh');
		}
		
		#get data.
		if(!isset($_SESSION['session'])){
			redirect('step_1', 'refresh');
		}else {
			$session_id			=	$_SESSION['session'];
			$cus_info			=	$this->apply_model->get_session_info($session_id);
			$country			=	$this->apply_model->get_country();
		}

		#assign data.
		$data['para_step1']	=	$cus_info;
		$data['country']	=	$country;
		$data['cus_id']		=	$session_id;

		$data['tpl_file']	=	"step_2";
		$this->load->view('pagelayout/index', $data);
	}
	
	
	
	function step_3(){
		if($_SERVER['REQUEST_METHOD']	==	'POST'){
			#get data from form.
			$payment				=	$this->input->post('payment');
			$extra_services			=	$this->input->post('extra_services');
			$cus_id					=	$this->input->post('customer_id_hidden');
			$visa_fee				=	$this->input->post('totalvisa_fee_hidden');
			$processingtime_fee		=	$this->input->post('total_processing_fee_hidden');
			$speedair_fee			=	$this->input->post('airfast_track_hidden');
			$pickup_fee				=	$this->input->post('carpick_up_hidden');
			
			if(isset($extra_services[0])){$airspeed_up		=	'yes';}else {$airspeed_up	=	'no';}
			if(isset($extra_services[1])){$carpick			=	'yes';}else {$carpick		=	'no';}
			if(isset($extra_services[2])){$tour_booking		=	'yes';}else {$tour_booking	=	'no';}
			if(isset($extra_services[3])){$hotel_booking	=	'yes';}else {$hotel_booking	=	'no';}
			
			if($airspeed_up == 'yes'){
				if($carpick	==	'yes'){
					$total_prices	=	$visa_fee + $processingtime_fee + $speedair_fee + $pickup_fee;
				}else {
					$total_prices	=	$visa_fee + $processingtime_fee + $speedair_fee;
				}
			}else {
				if($carpick	==	'yes'){
					$total_prices	=	$visa_fee + $processingtime_fee + $pickup_fee;
				}else {
					$total_prices	=	$visa_fee + $processingtime_fee;
				}
			}
			
			#update customer's info.
			$info					=	array();
			$info['airfast_track']	=	$airspeed_up;
			$info['carpick_up']		=	$carpick;
			$info['tour_booking']	=	$tour_booking;
			$info['hotel_booking']	=	$hotel_booking;
			$info['total_prices']	=	$total_prices;
			$info['pay_method']		=	$payment;
			$this->apply_model->update_customer_info($cus_id, $info);
			
			#make an invoice.
			$invoice				=	array();
			$invoice['customer_id']	=	$cus_id;
			$invoice['time']		=	date('Y-m-d H:i:s');
			$this->apply_model->make_invoice($invoice);
			
			#redirect to payment.
			redirect('apply/payment/'.$cus_id, 'refresh');
		}
		
		#get data .
		if(!isset($_SESSION['session'])){
			redirect('step_1', 'refresh');
		}
		$session_id				=	$_SESSION['session'];
		$customer_id			=	$this->uri->segment(2);
		$apply_info				=	$this->apply_model->get_apply_info($customer_id);
		$contact_info			=	$this->apply_model->get_customers_info($customer_id);
		
		$number_visa			=	$contact_info['amount_visa'];
		$type_visa				=	$contact_info['type_visa'];
		$service				=	$contact_info['services'];
		$total_service			=	0;
		
		#calculate visa fee.
		$price					=	$this->apply_model->get_price($type_visa);
		$group_prices			=	explode('|', $price['prices']);
		switch ($number_visa){
			case ($number_visa >=1 && $number_visa <= 2 ): 
				$fee_per_each	=	$group_prices[0];
				break;
			case ($number_visa >=3 && $number_visa <= 5 ):	
				$fee_per_each	=	$group_prices[1];
				break;
			case ($number_visa >= 6 && $number_visa <= 9 ):
				$fee_per_each	=	$group_prices[2];
				break;
			case ($number_visa >= 10):
				$fee_per_each	=	$group_prices[3];
				break;		
		}
		if($service	==	'urgent'){
			$service_fee		=	$price['urgent_service'];
		}else{
			$service_fee		=	0;
		} 
		
		$total_visa_fee			=	$fee_per_each * $number_visa;
		
		#calculate extra services fee.
		$airfast_track			=	$price['airfast_track'];
		$carpick_up				=	explode('|', $price['carpick_up']);
		
		switch ($number_visa){
			case ($number_visa >= 1 && $number_visa <= 2):
				$car_service	=	$carpick_up[0];
				break;
			case ($number_visa >= 3 && $number_visa <= 5):
				$car_service	=	$carpick_up[1];
				break;
			case ($number_visa >= 6):
				$car_service	=	$carpick_up[2];
				break;
		}
		
		#validate expiration date changing.
		$date_arrival			=	$contact_info['date_arrival'];

		$validate_date_exit		=	explode('/', $date_arrival);
		$date_arrival			=	$validate_date_exit[1];
		$month_arrival			=	$validate_date_exit[0];
		$year_arrival			=	$validate_date_exit[2];
		
		$date_expire_changing	=	$date_arrival;
		switch ($month_arrival){
		case 7:
			$month_expire_changing	=	1;
			$year_expire_changing	=	$year_arrival + 1;
			break;
			case 8:
			$month_expire_changing	=	2;
			$year_expire_changing	=	$year_arrival + 1;
			break;
			case 9:
			$month_expire_changing	=	3;
			$year_expire_changing	=	$year_arrival + 1;
			break;
			case 10:
			$month_expire_changing	=	4;
			$year_expire_changing	=	$year_arrival + 1;
			break;
			case 11:
			$month_expire_changing	=	5;
			$year_expire_changing	=	$year_arrival + 1;
			break;
			case 12:
			$month_expire_changing	=	6;
			$year_expire_changing	=	$year_arrival + 1;
			break;
			default:
			$month_expire_changing	=	$month_arrival + 6;
			$year_expire_changing	=	$year_arrival;
			break;
		}
		
	
		#assign data.
		$data['apply_info']				=	$apply_info;
		$data['contact_info']			=	$contact_info;
		$data['total_visa_fee']			=	$total_visa_fee;
		$data['each_visa_fee']			=	$fee_per_each;
		$data['processing_fee']			=	$service_fee;
		$data['total_processing_fee']	=	$service_fee * $number_visa;
		$data['airfast_track_fee']		=	$airfast_track;
		$data['total_airfast_track_fee']=	$number_visa * $airfast_track;
		$data['carpick_up_fee']			=	$car_service;
		$data['customer_id']			=	$customer_id;
		$data['number_applicants']		=	$number_visa;
		$data['timezone']				=	+ intval(7); //(GMT +7:00)
		$data['country']				=	$this->apply_model->get_country();
		$data['date_ex_changing']		=	$date_expire_changing;
		$data['month_ex_changing']		=	$month_expire_changing;
		$data['year_ex_changing']		=	$year_expire_changing;
		
		$data['tpl_file']				=	"step_3";
		$this->load->view('pagelayout/index', $data);
	}
	
	
	
	function payment(){
		$cus_id			=	$this->uri->segment(3);
		$payment_info	=	$this->apply_model->get_customers_info($cus_id);
		if(empty($_SESSION['session'])){
			redirect('apply/step1', 'refresh');
		}
		
		if($payment_info['pay_method'] == 'paypal'){
			$_SESSION['amount']			=	$payment_info['total_prices'];
			$_SESSION['payer_email']	=	$payment_info['email'];
			$_SESSION['item_name'] 		= 	"Vietnam visa on arrival - ".$payment_info['type_visa'];
			
			redirect(base_url().'paypal.php');
		}
		
		if($payment_info['pay_method']	==	'western'){
			exit('damn');
		}
		
		if($payment_info['pay_method']  == 'onepay'){
			
			
			$SECURE_SECRET = "A1F30E4982BFD225AE195663A435F1D1";

			$invoive='hello'; 
			    
			$vpc_MerchTxnRef = $invoive."-".time();
			$time = time();

			unset($_POST);
			
	    	$_POST['Title'] = 'DELTA TOUR';
			$_POST['virtualPaymentClientURL'] = "https://onepay.vn/vpcpay/vpcpay.op";
			$_POST['vpc_Version'] = "1";
			$_POST['vpc_Merchant'] = "VNBTRAVEL";
			$_POST['vpc_AccessCode'] = "CD84C08E";
			$_POST['vpc_Amount'] = '100';
			$_POST['vpc_Command'] = "pay";
			$_POST['vpc_MerchTxnRef'] = $vpc_MerchTxnRef;
			$_POST['vpc_OrderInfo'] = $invoive;
			$_POST['vpc_Locale'] = "en";

			$_POST['vpc_ReturnURL'] = base_url()."return_onepay";


			$_POST['vpc_TicketNo'] = $_SERVER['REMOTE_ADDR'];
			
			
			$vpcURL = $_POST["virtualPaymentClientURL"] . "?";
			
			unset($_POST["virtualPaymentClientURL"]); 

			$_POST['AgainLink']=urlencode($_SERVER['HTTP_REFERER']);

			$md5HashData = $SECURE_SECRET;
			
			ksort ($_POST);
			
			// set a parameter to show the first pair in the URL
			$appendAmp = 0;
			
			foreach($_POST as $key => $value) {
			
			    // create the md5 input and URL leaving out any fields that have no value
			    if (strlen($value) > 0) {
			        
			        // this ensures the first paramter of the URL is preceded by the '?' char
			        if ($appendAmp == 0) {
			            $vpcURL .= urlencode($key) . '=' . urlencode($value);
			            $appendAmp = 1;
			        } else {
			            $vpcURL .= '&' . urlencode($key) . "=" . urlencode($value);
			        }
			        $md5HashData .= $value;
			    }
			}
			
			// Create the secure hash and append it to the Virtual Payment Client Data if
			// the merchant secret has been provided.
			if (strlen($SECURE_SECRET) > 0) {
			    $vpcURL .= "&vpc_SecureHash=" . strtoupper(md5($md5HashData));
			}
//			die;
			// FINISH TRANSACTION - Redirect the customers using the Digital Order
			// ===================================================================
			header("Location: ".$vpcURL);
			die;
			// *******************
			// END OF MAIN PROGRAM
			// 
		}
		
	}
	
	
	
	function return_onepay(){

	
		$SECURE_SECRET = "A1F30E4982BFD225AE195663A435F1D1";
	
		$orderInfo       = $this->null2unknown($_GET["vpc_OrderInfo"]);
		$filterOrderId = explode('-',$orderInfo);
	
		if(count($filterOrderId) != 2)
		{
			die("False 1");
		}
		$orderId = $filterOrderId[1];
	
		$vpc_Txn_Secure_Hash = $_GET["vpc_SecureHash"];
		unset($_GET["vpc_SecureHash"]);
	
		// set a flag to indicate if hash has been validated
		$errorExists = false;
	
		if (strlen($SECURE_SECRET) > 0 && $_GET["vpc_TxnResponseCode"] != "7" && $_GET["vpc_TxnResponseCode"] != "No Value Returned") {
	
			$md5HashData = $SECURE_SECRET;
	
			// sort all the incoming vpc response fields and leave out any with no value
			foreach($_GET as $key => $value) {
				if ($key != "vpc_SecureHash" or strlen($value) > 0) {
					$md5HashData .= $value;
				}
			}
	
			if (strtoupper($vpc_Txn_Secure_Hash) == strtoupper(md5($md5HashData))) {
				$hashValidated = "CORRECT";
			} else {
				$hashValidated = "INVALID HASH";
				$errorExists = true;
			}
		} else {
			// Secure Hash was not validated, add a data field to be displayed later.
			$hashValidated = "<FONT color='orange'><strong>Not Calculated - No 'SECURE_SECRET' present.</strong></FONT>";
		}
	
		$txnResponseCode = $this->null2unknown($_GET["vpc_TxnResponseCode"]);
	
	
		if($txnResponseCode == '0')
		{
			$this->apply_model->update_payment($orderId,$invoice,$session);
				
			$this->apply_model->send_mail_payment($orderId,$invoice,$session);
			if(!$iframe)
			{
				redirect(base_url()."thankyou.html");
			} else {
				redirect(base_url()."thankyou.html?iframe=true");
			}
			die();
		} else {
			if(!$iframe)
			{
				redirect(base_url()."payagain.html");
			} else {
				redirect(base_url()."payagain.html?iframe=true");
			}
			die();
		}
	}
	
	
	function null2unknown($data) {
		if ($data == "") {
			return "No Value Returned";
		} else {
			return $data;
		}
	}
	
	
	function change_type(){
		$type_id	=	$_POST['type_id'];
		
		
		if($type_id == "1 month single"){
			echo "<p>".$type_id.' entry' ."<br>(30-day stay, only 1 time entry/exit)</p>";
		}
		
		if($type_id == "3 months single"){
			echo "<p>".$type_id.' entry' ."<br>(90-day stay, only 1 time entry/exit)</p>";
		}
		
		if($type_id == "1 month multiple"){
			echo "<p>".$type_id.' entry' ."<br>(30-day stay, multiple entry/exit)</p>";
		}

		if($type_id == "3 months multiple"){
			echo "<p>".$type_id.' entry' ."<br>(90-day stay, multiple entry/exit)</p>";
		}
		
	}
	
	
	
	function change_number(){
		$number_id	=	$_POST['number_id'];
		if($number_id >1){
			echo "<p>".$number_id.' Applicants' ."</p>";
		}else {
			echo "<p>".$number_id.' Applicant' ."</p>";
		}
	}
	
	
	
	function change_purpose(){
		
		$purpose_visit	=	$_POST['purpose_id'];
		
		if($purpose_visit == ''){
			echo 'Please Select';
		}
		if($purpose_visit == 'vacation'){
			echo 'Vacation';
		}
		if($purpose_visit == 'business'){
			echo 'Business';
		}
		if($purpose_visit == 'family_visit'){
			echo 'Family/Friend visit';
		}
		if($purpose_visit == 'other'){
			echo 'Other';
		}
	}

	

	
	
	function change_contact_info(){
		if(isset($_POST['change_arrival_date'])){$data['date_arrival']		=	$_POST['change_arrival_date'];}
		if(isset($_POST['change_exit_date'])){$data['date_exit']			=	$_POST['change_exit_date'];}
		if(isset($_POST['change_arrival_port'])){$data['arrival_port']		=	$_POST['change_arrival_port'];}else{$data['change_arrival_port']="";}
		if(isset($_POST['change_flight_number'])){$data['flight_number']	=	$_POST['change_flight_number'];}
		if(isset($_POST['change_rush_service'])){$data['services']			=	$_POST['change_rush_service'];}else{$data['change_rush_service']="";}

		$customer_id		=	$_POST['change_customer_id_hidden'];
		$this->apply_model->contact_info_changing($customer_id, $data);
		
		redirect('step_3/'.$customer_id, 'refresh');
	}
	
	
	function change_apply_info(){
		$data['full_name']		=	$_POST['change_full_name'];
		$data['passport']		=	$_POST['change_passport_number'];
		$data['expiration']		=	$_POST['change_passport_expiration'];
		$data['nationality']	=	$_POST['change_nationality'];
		$data['birth_date']		=	$_POST['change_birth_date'];
		$data['gender']			=	$_POST['change_gender'];
		
		$apply_id				=	$_POST['apply_id'];
		$this->apply_model->apply_info_changing($apply_id, $data);
		
		$customer_id			=	$_POST['change_customer_id_hidden'];
		redirect('step_3/'.$customer_id, 'refresh');
		
		
	}
		
	
	function get_price_ajax(){
		$number_visa	=	$_POST['number_visa'];
		$type_visa		=	$_POST['type_visa'];
		$service		=	$_POST['service'];
		
		
		$total_service	=	0;
		
		$price			=	$this->apply_model->get_price($type_visa);
		
		$group_prices	=	explode('|', $price['prices']);
		
		switch ($number_visa){
			case ($number_visa >=1 && $number_visa <= 2 ): 
				$fee_per_each	=	$group_prices[0];
				break;
			case ($number_visa >=3 && $number_visa <= 5 ):	
				$fee_per_each	=	$group_prices[1];
				break;
			case ($number_visa >= 6 && $number_visa <= 9 ):
				$fee_per_each	=	$group_prices[2];
				break;
			case ($number_visa >= 10):
				$fee_per_each	=	$group_prices[3];
				break;		
		}
		
		if($service	==	'urgent'){
			$total_service		=	$number_visa * $price['urgent_service'];
		}elseif ($service	==	'super_urgent'){
			die('---');
		}
		echo ($fee_per_each * $number_visa + $total_service ).' USD';
	}
	
	
	
	function validate_date_exit_ceiling(){
		#get data form form.
		$get_date_arrival			=	$_POST['date_arrival'];
		$type_of_visa				=	$_POST['type_of_visa'];
		
		#get detail of arrival date includes date, month, year.
		if($get_date_arrival != ""){
			$validate_date_exit		=	explode('/', $get_date_arrival);
			$date_arrival			=	$validate_date_exit[1];
			$month_arrival			=	$validate_date_exit[0];
			$year_arrival			=	$validate_date_exit[2];
			
			
			#validate date of exit.
			if($type_of_visa == '1 month single' || $type_of_visa == '1 month multiple'){
				if($month_arrival == 12){
					$date_exit		=	$date_arrival;
					$month_exit		=	1;
					$year_exit		=	$year_arrival + 1;
				}else {
					$date_exit		=	$date_arrival;
					$month_exit		=	$month_arrival + 1;
					$year_exit		=	$year_arrival;
				}
			}
			
			if($type_of_visa == '3 months single' || $type_of_visa == '3 months multiple'){
				$date_exit			=	$date_arrival;
				switch ($month_arrival){
					case 10:
						$month_exit	=	1;
						$year_exit	=	$year_arrival + 1;
						break;
					case 11:
						$month_exit	=	2;
						$year_exit	=	$year_arrival + 1;
						break;
					case 12:
						$month_exit	=	3;
						$year_exit	=	$year_arrival + 1;
						break;
					default:
						$month_exit	=	$month_arrival + 3;
						$year_exit	=	$year_arrival;
						break;
				}
			}
			echo "<input type='hidden' class='validate[dateExitRequired, exitDateRange[exitGroup]] text-input datepicker' id='exit_date_ceiling' value='".$month_exit.'/'.$date_exit.'/'.$year_exit."'name='exit_date_hid_ceiling' />";
		}
	}
	
	
	function validate_date_exit_floor(){
		#get data form form.
		$date_arrival		=	$_POST['date_arrival'];
	
		#get detail of arrival date includes date, month, year.
		if($date_arrival != ""){
			echo "<input type='hidden' class='validate[dateExitRequired, exitDateRange[exitGroup]] text-input datepicker' id='exit_date_floor' value='".$date_arrival."' name='exit_date_hid_floor' />";
		}
	}
	
	
	
	function change_date_exit_ceiling(){
		#get data form form.
		$get_date_arrival		=	$_POST['date_arrival'];
		$type_of_visa			=	$_POST['type_of_visa'];
		
		#get detail of arrival date includes date, month, year.
		if($get_date_arrival != ""){
			$validate_date_exit		=	explode('/', $get_date_arrival);
			$date_arrival			=	$validate_date_exit[1];
			$month_arrival			=	$validate_date_exit[0];
			$year_arrival			=	$validate_date_exit[2];
			
			
			#validate date of exit.
			if($type_of_visa == '1 month single' || $type_of_visa == '1 month multiple'){
				if($month_arrival == 12){
					$date_exit		=	$date_arrival;
					$month_exit		=	1;
					$year_exit		=	$year_arrival + 1;
				}else {
					$date_exit		=	$date_arrival;
					$month_exit		=	$month_arrival + 1;
					$year_exit		=	$year_arrival;
				}
			}
			
			if($type_of_visa == '3 months single' || $type_of_visa == '3 months multiple'){
				$date_exit			=	$date_arrival;
				switch ($month_arrival){
					case 10:
						$month_exit	=	1;
						$year_exit	=	$year_arrival + 1;
						break;
					case 11:
						$month_exit	=	2;
						$year_exit	=	$year_arrival + 1;
						break;
					case 12:
						$month_exit	=	3;
						$year_exit	=	$year_arrival + 1;
						break;
					default:
						$month_exit	=	$month_arrival + 3;
						$year_exit	=	$year_arrival;
						break;
				}
			}
			echo "<input type='hidden' class='validate[dateExitRequired, exitDateRange[exitGroup]] text-input datepicker' id='change_exit_date_ceiling' id='exit_date_ceiling' value='".$month_exit.'/'.$date_exit.'/'.$year_exit."'name='change_exit_date_hid_ceiling' />";
		}
	}
	
	
	
	function change_date_exit_floor(){
		$date_arrival	=	$_POST['date_arrival'];
		echo '<input type="hidden" class="validate[dateExitRequired, exitDateRange[exitGroup]] text-input datepicker" id="change_exit_date_floor" value="'.$date_arrival.'" name="change_exit_date_hid_floor" />';
	}
	

}

/* End of file apply.php */
/* Location: ./application/controllers/apply.php */